import React from 'react'
import { Form, Input, Button, message } from 'antd';
// import Particles from 'react-particles';
import axios from 'axios'
import './index.css'
const Login = (props) => {
    const onFinish = (values) => {
        // console.log('Success:', values);
        axios.get(`/users?username=${values.username}&password=${values.password}&roleState=true&_expand=role`)
        .then(res=>{
            if(res.data.length===0){
                message.error("用户名或密码不匹配")
            }else{
                localStorage.setItem("token", JSON.stringify(res.data[0]))
                props.history.push("/")
            } 
        })
      };
    return (
        <div style={{backgroundColor: 'rgb(35,39,65)', height: '100vh'}}>
            <div className="formContaniner">
            {/* <Particles /> */}
            <div className="info">全球新闻发布管理系统</div>
                <Form
                    name="basic"
                    onFinish={onFinish}
                    >
                    <Form.Item
                        label="用户名"
                        name="username"
                        rules={[
                        {
                            required: true,
                            message: '请输入用户名!',
                        },
                        ]}
                        labelAlign="left"
                    >
                        <Input placeholder="请输入用户名"/>
                    </Form.Item>
                    <Form.Item
                        label="&nbsp;&nbsp;&nbsp;密 码"
                        name="password"
                        rules={[
                        {
                            required: true,
                            message: '请输入密码!',
                        },
                        ]}
                    >
                        <Input.Password placeholder="请输入密码"/>
                    </Form.Item>
                    <Form.Item>
                        <Button type="primary" htmlType="submit" style={{marginLeft: "17px"}}>
                            登录
                        </Button>
                    </Form.Item>
                    </Form>
            </div>
        </div>
        );
    };

export default Login;
